import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);


const routes = [{
  path:"*",
  redirect:"/home",
  meta: {
    title: '首页'
  }
},{
  name: 'home',
  component: () => {
    return import('./view/home');
  },
  meta: {
    title: '首页'
  }
}, {
  name:"about",
  component: () => {
    return import('./view/about');
  },
  meta: {
    title: '关于'
  }
}];

// 转换地址
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});


var router = new Router({
  mode:"hash",
  routes
})


router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});

export default router;